﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Z2.Core
{
	public class ActionTimer
	{

		private DateTime m_timer;
		private double m_interval;
		private bool m_enabled;

		public ActionTimer()
		{
			this.m_timer = DateTime.Now;
		}

		public ActionTimer(double interval) 
			: this()
		{
			this.m_interval = interval;
		}

		public double Interval
		{
			get { return this.m_interval; }
			set { this.m_interval = value; }
		}

		public bool Enabled
		{
			get { return this.m_enabled; }
			set { this.m_enabled = value; }
		}

		public bool Now()
		{
			if (!this.m_enabled) return false;
			bool now = DateTime.Now.Subtract(this.m_timer).TotalMilliseconds >= this.m_interval;
			if (now) this.m_timer = DateTime.Now;
			return now;
		}


	}
}
